#!/usr/bin/env python
# coding=utf-8

import datetime, subprocess

tests =(('58.211.11.9'    , u'电信 江苏'  ),
        ('121.10.119.194' , u'电信 广东'  ),
        ('110.85.5.32'    , u'电信 福建'  ),
        ('61.153.87.90'   , u'电信 浙江'  ),
        ('219.153.71.71'  , u'电信 重庆'  ),
        ('117.41.160.34'  , u'电信 江西'  ),
        ('124.232.155.58' , u'电信 湖南'  ),
        ('221.1.220.181'  , u'联通 山东'  ),
        ('218.8.242.163'  , u'联通 黑龙江'),
        ('61.135.169.125' , u'联通 北京'  ),
        ('220.181.6.175'  , u'电信 北京'  ))

def test_ip(ip):
    p = subprocess.Popen(['ping', '-c' , '5' , ip], stdout=subprocess.PIPE)
    out = p.communicate()[0]
    result = '\n'.join(out.split('\n')[-3:-1])
    return result

if __name__ == '__main__' :

    print 'start test, %s\n' % (datetime.datetime.now().isoformat(' '),)

    for test in tests:
        ip   = test[0]
        desc = test[1]

        result = test_ip(ip)

        print '%s %s' % (ip, desc)
        print result
        print ''


